class Solution {
public:
    void merge(int A[], int m, int B[], int n) {
        int ia=m-1, ib=n-1, ic=n+m-1;
        while (ia>=0 || ib>=0) {
            if (ib<0 || (ia>=0 && A[ia]>B[ib])) {
                A[ic]=A[ia];
                --ia;
            } else {
                A[ic]=B[ib];
                --ib;
            }
            --ic;
        }
    }
};
